package edu.hawaii.wicket.page.water;

import java.util.Map;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.Radio;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;
import edu.hawaii.wicket.ExampleApplicationSession;
import edu.hawaii.wicket.page.BasePage;
import edu.hawaii.wicket.page.ExternalImageUrl;
import edu.hawaii.wicket.page.ac.ACPage;
import edu.hawaii.wicket.page.aquaponics.AquaponicsPage;
import edu.hawaii.wicket.page.lighting.LightingPage;
import edu.hawaii.wicket.page.security.SecurityPage;

/**
 * Creates the Water Page.
 * @author Gregory L Burgess
 *
 */
public class WaterPage extends BasePage {
    
  private static final ResourceReference SIDE_BAR = new ResourceReference(
          WaterPage.class,"side-bar.png");
  private static final ResourceReference LOGO = new ResourceReference(
          WaterPage.class,"logo.png");

  private static final long serialVersionUID = 1L;

  /**
   * Creates the water page. 
   */
  public WaterPage() {

    add(new Image("sidebar", new Model<ResourceReference>(SIDE_BAR)));
    add(new Image("logo", new Model<ResourceReference>(LOGO)));

    //form to pass data
    Form<String> form = new Form<String>("form");
    add(form);
    
    //image for tank levels
    ResourceReference tank = new ResourceReference(WaterPage.class, "TankLevels.png");
    form.add(new Image ("image3",new Model<ResourceReference>(tank)));

    //data output for water heater settings
    form.add(new Label("sugTemp", "90 F"));
    form.add(new Label("tankTemp", "98 F"));
    form.add(new Label("tankVol", "120 g"));
    
    //fields for smart temp
    form.add(new TextField<String>("durationBox"));
    form.add(new TextField<String>("minTempBox"));
    form.add(new TextField<String>("usageBox"));
    
    //manual control for shower temp
    form.add(new TextField<String>("manualBox"));
    form.add(new Button("calc") {
      private static final long serialVersionUID = 1L;

      /** Display the page again, now with the updated values of field1 and field2. */
      @Override
      public void onSubmit() {
        setResponsePage(WaterPage.class);
      }
    });
    form.add(new Button("change") {
      private static final long serialVersionUID = 1L;

      /** Display the page again, now with the updated values of field1 and field2. */
      @Override
      public void onSubmit() {
        setResponsePage(WaterPage.class);
      }
    });
    
    //radio buttons for water heater on/off switch
    RadioGroup<String> group = new RadioGroup<String>("power");
    group.add(new Radio<String>("on"));
    group.add(new Radio<String>("off"));
    form.add(group);
    
    //long URL is long...
    String url = "http://chart.apis.google.com/chart?chf=bg,";
    url += "s,000000&chxl=1:|12%3A00|1%3A00|2%3A00|3%3A00|4";
    url += "%3A00|5%3A00|6%3A00|7%3A00|8%3A00|9%3A00&chxp=1,2,10,";
    url += "20,30,40,50,60,70,80,90&chxr=0,0,8&chxt=y,x&chs=700x290";
    url += "&cht=lc&chco=0000FF,FF9900&chd=s:u4630lju,kjdaacaddcffeZV";
    url += "cfdil&chdl=Total|Hot+&chg=10,-1,0,0&chls=3,4,0|3&chm=B,0000";
    url += "408C,0,0,0&chtt=Water+Consumption+Over+Time+(Gallons%2FHr)&chts=FFFFFF,14";
    add(new ExternalImageUrl("waterChart", url,"700","290"));
    
    
    
    
    //=========================================================================================
  //=========================================================================================
  //=========================================================================================
  //=========================================================================================
 // Now add the links that go in the tabs. 
    add(new Link<String>("AquaponicsPageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to HomePage. */
      @Override
      public void onClick() {
        setResponsePage(new AquaponicsPage());
      }
      }
    );
    
    add(new Link<String>("LightingPageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to ListPage. */
      @Override
      public void onClick() {
        setResponsePage(new LightingPage());
      } 
      }
    );
    
    add(new Link<String>("SecurityPageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to FormPage. */
      @Override
      public void onClick() {
        setResponsePage(new SecurityPage());
      }
      }
    );
    
    add(new Link<String>("ClimatePageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to TablePage. */
      @Override
      public void onClick() {
        setResponsePage(new ACPage());
      }
      }
    );
    
    add(new Link<String>("WaterPageLink") {
      private static final long serialVersionUID = 1L;
      /** Upon clicking this link, go to TablePage. */
      @Override
      public void onClick() {
        setResponsePage(new WaterPage());
      }
      }
    );
    
  }
  
  /**
   * Returns the property map associated with this user's session.
   * @return The session's property map.
   */
  public Map<String, String> getSessionProperties() {
    return ((ExampleApplicationSession)getSession()).getProperties();   
  }
}
